import { requestApi } from '../../api/request'
const app = getApp()
Page({
    data: {
        search:true,
        preloading:true,
        param:{
            action:'index',
            page:1,
        },
        newslist:[],
        pagename:'首页'
    },
    onInit(){
        let param = this.data.param
        this.getdata(param)
        // console.log(param)
    },
    onLoad() {
        // 监听页面加载的生命周期函数
    },
    onReachBottom: function() {
        // 上拉触底
        let page = this.data.param.page
        page++
        this.data.param.page = page
        let param = {
            action:'index',
            page:this.data.param.page
        }
        requestApi(param).then(
            res => {
                // console.log(res)
                let newslistitem = res.data.news
                // console.log(newslistitem)
                let newslist = this.data.newslist.concat(newslistitem)
                // console.log(newslist)
                this.setData({
                    newslist
                })
            }
        )
    },
    getdata(param){
        requestApi(param).then(
            res => {
                console.log(res)
                let banner = res.data.banner
                let newslist = res.data.news
                let site = res.data.site
                // site.img = banner[0].banner
                this.setData({
                    preloading:false,
                    banner,
                    newslist,
                })
                app.getTdk(site)
            }
        )
    }
})
